from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-13 14:08:01.989471
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 13, May, 2021
Time: 14:08:07
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2173
Nobs: 290.000 HQIC: -48.8999
Log likelihood: 3543.22 FPE: 3.67260e-22
AIC: -49.3562 Det(Omega_mle): 2.70685e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.373194 0.112904 3.305 0.001
L1.Burgenland 0.069960 0.058604 1.194 0.233
L1.Kärnten -0.225242 0.052095 -4.324 0.000
L1.Niederösterreich 0.103766 0.124247 0.835 0.404
L1.Oberösterreich 0.227368 0.121347 1.874 0.061
L1.Salzburg 0.283581 0.066596 4.258 0.000
L1.Steiermark 0.110235 0.085104 1.295 0.195
L1.Tirol 0.126482 0.059120 2.139 0.032
L1.Vorarlberg -0.032827 0.054289 -0.605 0.545
L1.Wien -0.029419 0.108006 -0.272 0.785
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.402461 0.130387 3.087 0.002
L1.Burgenland 0.003497 0.067679 0.052 0.959
L1.Kärnten 0.327224 0.060162 5.439 0.000
L1.Niederösterreich 0.117452 0.143486 0.819 0.413
L1.Oberösterreich -0.069104 0.140137 -0.493 0.622
L1.Salzburg 0.233808 0.076908 3.040 0.002
L1.Steiermark 0.092668 0.098282 0.943 0.346
L1.Tirol 0.135654 0.068274 1.987 0.047
L1.Vorarlberg 0.153442 0.062696 2.447 0.014
L1.Wien -0.388957 0.124730 -3.118 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.258514 0.057574 4.490 0.000
L1.Burgenland 0.107074 0.029884 3.583 0.000
L1.Kärnten -0.012825 0.026565 -0.483 0.629
L1.Niederösterreich 0.090150 0.063358 1.423 0.155
L1.Oberösterreich 0.281813 0.061879 4.554 0.000
L1.Salzburg 0.018988 0.033960 0.559 0.576
L1.Steiermark -0.001128 0.043398 -0.026 0.979
L1.Tirol 0.069857 0.030147 2.317 0.020
L1.Vorarlberg 0.077174 0.027684 2.788 0.005
L1.Wien 0.112254 0.055076 2.038 0.042
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190194 0.054902 3.464 0.001
L1.Burgenland 0.027619 0.028497 0.969 0.332
L1.Kärnten 0.009453 0.025332 0.373 0.709
L1.Niederösterreich 0.060850 0.060417 1.007 0.314
L1.Oberösterreich 0.397874 0.059007 6.743 0.000
L1.Salzburg 0.085011 0.032383 2.625 0.009
L1.Steiermark 0.131460 0.041383 3.177 0.001
L1.Tirol 0.050498 0.028748 1.757 0.079
L1.Vorarlberg 0.082591 0.026399 3.129 0.002
L1.Wien -0.036946 0.052520 -0.703 0.482
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.418102 0.108088 3.868 0.000
L1.Burgenland 0.100314 0.056104 1.788 0.074
L1.Kärnten 0.010430 0.049873 0.209 0.834
L1.Niederösterreich 0.045880 0.118948 0.386 0.700
L1.Oberösterreich 0.115552 0.116171 0.995 0.320
L1.Salzburg 0.064103 0.063755 1.005 0.315
L1.Steiermark 0.063265 0.081474 0.777 0.437
L1.Tirol 0.202660 0.056598 3.581 0.000
L1.Vorarlberg 0.040313 0.051974 0.776 0.438
L1.Wien -0.056478 0.103399 -0.546 0.585
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.212268 0.084614 2.509 0.012
L1.Burgenland -0.013902 0.043920 -0.317 0.752
L1.Kärnten -0.005272 0.039042 -0.135 0.893
L1.Niederösterreich -0.005243 0.093115 -0.056 0.955
L1.Oberösterreich 0.416502 0.090941 4.580 0.000
L1.Salzburg 0.014410 0.049909 0.289 0.773
L1.Steiermark -0.031083 0.063780 -0.487 0.626
L1.Tirol 0.161564 0.044306 3.647 0.000
L1.Vorarlberg 0.058913 0.040686 1.448 0.148
L1.Wien 0.197547 0.080943 2.441 0.015
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199289 0.103279 1.930 0.054
L1.Burgenland 0.025669 0.053608 0.479 0.632
L1.Kärnten -0.072813 0.047654 -1.528 0.127
L1.Niederösterreich -0.031861 0.113655 -0.280 0.779
L1.Oberösterreich 0.005265 0.111002 0.047 0.962
L1.Salzburg 0.090174 0.060919 1.480 0.139
L1.Steiermark 0.313264 0.077849 4.024 0.000
L1.Tirol 0.458531 0.054080 8.479 0.000
L1.Vorarlberg 0.148451 0.049661 2.989 0.003
L1.Wien -0.133774 0.098799 -1.354 0.176
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203649 0.122464 1.663 0.096
L1.Burgenland 0.040398 0.063566 0.636 0.525
L1.Kärnten -0.073516 0.056506 -1.301 0.193
L1.Niederösterreich 0.115867 0.134768 0.860 0.390
L1.Oberösterreich 0.011499 0.131622 0.087 0.930
L1.Salzburg 0.194899 0.072235 2.698 0.007
L1.Steiermark 0.129208 0.092310 1.400 0.162
L1.Tirol 0.055153 0.064126 0.860 0.390
L1.Vorarlberg 0.107788 0.058887 1.830 0.067
L1.Wien 0.222852 0.117151 1.902 0.057
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.484414 0.068696 7.052 0.000
L1.Burgenland -0.011673 0.035657 -0.327 0.743
L1.Kärnten -0.018091 0.031697 -0.571 0.568
L1.Niederösterreich 0.111973 0.075597 1.481 0.139
L1.Oberösterreich 0.305575 0.073833 4.139 0.000
L1.Salzburg 0.025576 0.040520 0.631 0.528
L1.Steiermark -0.045895 0.051781 -0.886 0.375
L1.Tirol 0.079535 0.035971 2.211 0.027
L1.Vorarlberg 0.104779 0.033032 3.172 0.002
L1.Wien -0.034131 0.065716 -0.519 0.604
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.161640 0.083981 0.171460 0.223187 0.073616 0.084166 0.000332 0.169424
Kärnten 0.161640 1.000000 0.053211 0.215817 0.188929 -0.066304 0.180199 0.022164 0.309864
Niederösterreich 0.083981 0.053211 1.000000 0.238804 0.096022 0.314115 0.142719 0.027010 0.312032
Oberösterreich 0.171460 0.215817 0.238804 1.000000 0.305647 0.262139 0.104482 0.061104 0.144022
Salzburg 0.223187 0.188929 0.096022 0.305647 1.000000 0.150647 0.070920 0.090326 0.035981
Steiermark 0.073616 -0.066304 0.314115 0.262139 0.150647 1.000000 0.095146 0.099979 -0.098351
Tirol 0.084166 0.180199 0.142719 0.104482 0.070920 0.095146 1.000000 0.154332 0.160919
Vorarlberg 0.000332 0.022164 0.027010 0.061104 0.090326 0.099979 0.154332 1.000000 -0.011704
Wien 0.169424 0.309864 0.312032 0.144022 0.035981 -0.098351 0.160919 -0.011704 1.000000